#!/bin/bash
# Here put anything that is needed to start the service.
# Note that currently this is run directly after install
# i.e. 'service apache2 start'
set -e

# This hook needs to be idempotent, so this could be run when ellis is
# already running, when it's running but not monitored by monit, when
# it's stopped but being monitored (so it's about to start), or stopped
# and unmonitored. To cover all these cases, restart ellis, restart monit,
# then finally have monit monitor ellis.  Note that restarting monit can
# fail because init will also restart it when it stops and restarting
# ellis can fail because monit will restart it.
service ellis restart || /usr/bin/true
service clearwater-monit restart || /usr/bin/true
sleep 1
monit monitor ellis
